package tcc.war.autenticador.bean;

import java.io.Serializable;
import java.util.Map;


import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;



import tcc.ejb.autenticador.bean.ProfissionalEjb;
import tcc.ejb.autenticador.entidade.Profissional;

@ManagedBean(name = "preferenciaUsuario")
@RequestScoped
public class PreferenciaUsuarioMBean implements Serializable {

	private static final long serialVersionUID = 6814795566698772934L;
	private String theme;
	private Profissional profissional;
	@EJB private ProfissionalEjb profissionalEjb;

	public String getTheme() {
		profissional = (Profissional) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("PROFISSIONAL");
		theme = profissional.getSkin();
		Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
		if(params.containsKey("theme")) {
			theme = params.get("theme");
		}
      	return theme;
	}

	public void setTheme(String theme) {
		profissional = (Profissional) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("PROFISSIONAL");
		profissional.setSkin(theme);
		FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("PROFISSIONAL",this.profissional);
		profissionalEjb.edit(profissional);
		this.theme = theme;
	}
}
